define(function (require, exports, module) {
    'use strict';
    var $ = require('jquery'),
        _ = require('underscore'),
        Backbone = require('backbone'),
        notify = require('js/utils/notify'),
        models = require('js/apps/report/models'),
        utils = require('js/utils/tools'),
        chart = require('js/utils/chart'),
        moment = require('moment'),
        helper = require('js/apps/report/common');

    var RechargeView = Backbone.View.extend({
        events: {
            'click #search': 'doSearch'
        },
        initialize: function (options) {
            this.options = options;
            this.model = new models.RechargeReport();
            this.model.bind('change reset', this.renderWithData, this);
        },
        doSearch: function () {
            this.options.dateRange = helper.getDateRange();
            this.options.userType = parseInt($('#userType').val());
            this.load();
        },
        render: function () {
            this.$el.html("");
            $(window).scrollTop(0);
            return this;
        },
        renderWithData: function () {
            this.$el.html(this.template({
                item: this.model.toJSON(),
                options: this.options
            }));
            helper.loadDatePicker(this.options);
            return this;
        },
        load: function () {
            this.model.fetch({
                reset: true,
                data: {
                    date_range: this.options.dateRange.join(','),
                    user_type: this.options.userType
                },
                error: function (c, r, o) {
                    notify.notifyResp(r);
                }
            })
        }
    });
    exports.List = Backbone.View.extend({
        el: "#content_wrapper",
        template: "report/Recharge.html",
        render: function () {
            var today = moment().format('YYYY-MM-DD'),
                dateRange = [today, today],
                view = new RechargeView({
                    dateRange: dateRange
                });
            view.template = this.template;
            this.$el.empty();
            this.$el.append(view.render().el);
            view.load();
            return this;
        }
    });

});